﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Threading;
using System.Globalization;

namespace Modellayer
{
    [DataContract]
    public class Show
    {
        [DataMember]
        public string showTime { get; set; }

        [DataMember]
        public ShowRoom showroom;

        [DataMember]
        public List<Seat> seats { get; set; }

        [DataMember]
        public Movie movie;

        [DataMember]
        public int showId {get; set;}


        public Show(Movie movie, ShowRoom showroom, int showId, string sTime)
        {
            this.movie = movie;
            this.showroom = showroom;
            this.showId = showId;
            this.showTime = sTime;
            createSeats(showId);
            
            
        }

        public Show()
        {
 
        }

        private void createSeats(int showId)
        {
            seats = new List<Seat>();
            int numberOfSeats = showroom.numberOfSeats;
            int index = 0;
            while (index < numberOfSeats)
            {
                Seat seat = new Seat(index, showId);
                seats.Add(seat);
                index++;
            }
        }
        public List<Seat> createSeatsOnNewShow(int showId, int numberOfSeats)
        {
            seats = new List<Seat>();
            
            
            int index = 0;
            while (index < numberOfSeats)
            {
                Seat seat = new Seat(index, showId);
                seats.Add(seat);
                index++;
            }
            return seats;
        }

       

        //public DateTime setShowTime()
        //{
        //    //get {return showTime;}
        //    //set {showTime = value; }
        //    DateTime tm = new DateTime();
        //    showTime = tm;
        //    return tm;
        //}

        //[DataMember]
        //public string getShowTime
        //{
        //    get { return showTime.ToString(); }

        //}

        public void lockSeat(int seatNumber)
        {
            findSeat(seatNumber).lockSeat();
        }

        public void reserveSeat(int seatNumber, int reservationId)
        {
            findSeat(seatNumber).reserveSeat(reservationId);
        }

        public void unLockSeat(int seatNumber)
        {
            findSeat(seatNumber).unLockSeat();
        }

        private Seat findSeat(int seatNumber)
        {
            int index = 0;
            Boolean found = false;
            while (index < seats.Count || found == true)
            {
                if (seats.ElementAt(index).seatNumber == seatNumber)
                {
                    found = true;
                }
                else
                {
                    index++;
                }
            }
            return seats.ElementAt(index);
        }

        //[DataMember]
        //public List<Seat> getSeats
        //{
        //    get;
        //    set;
        //}

        //[DataMember]
        //public int getSetShowId
        //{
        //    get { return showId; }
        //    set { showId = value; }
        //}

        //[DataMember]
        //public ShowRoom getShowRoom
        //{
        //    get;
        //    set;
        //}

        //public int getShowRoomNumber()
        //{
        //    return showroom.showRoomNumber;
        //}

        [DataMember]
        public List<Movie> getAllShow
        {
            get;
            set;
        }

        //[DataMember]
        //public Movie getMovieOnShow
        //{
        //    get;
        //    set;
        //}

        public List<ShowRoom> getAllShowRoom
        {
            get;
            set;
        }

    }
}
